<template>
  <div class="main">
    <div class="add" v-if="roles.indexOf('admin') != -1" @click="edit(form.ID)">编辑</div>
    <van-cell-group :border="border">
      <van-field class="input_text" label="证书名称" :value="form.CertName" readonly />
      <van-field class="input_text" label="证书类别" :value="form.CertTypeName" readonly />
      <van-field class="input_text" label="证书编号" :value="form.UserCertCode" readonly />
    </van-cell-group>
    <van-cell-group :border="border" style="margin-top: 10px">
      <van-field class="input_text" label="员工" :value="form.ChnName" readonly />
      <van-field class="input_text" label="发证机构" :value="form.CertOrg" readonly />
      <van-field class="input_text" label="发证日期" :value="form.PublishDate" readonly />
    </van-cell-group>
    <van-cell-group :border="border" style="margin-top: 10px">
      <van-field class="input_text" label="是否需要复审" :value="form.IsNeedReview ? '是' : '否'" readonly />
      <van-cell v-if="form.IsNeedReview" title="证书复审记录" is-link @click="goReview(form.UCCode)" />
      <van-field v-if="form.IsNeedReview" class="input_text" label="最近复审日期" :value="form.ReviewDate" readonly />
      <van-field v-if="form.IsNeedReview" class="input_text" label="下次复审日期" :value="form.NextReviewDate" readonly />

      <van-field class="input_text" label="证书管理员" :value="form.CertManagerChnName" readonly />
      <!-- <van-field
        class="input_text"
        label="证书附件"
        :value="form.Attachs2"
        readonly
      /> -->
      <van-field label="证书附件" readonly class="input_text_block">
        <template #input>
          <div v-for="(item, index) in fileList" :key="index"><a style="color:blue" @click="_goEnclosure(item)">
              {{ item.AttName }}{{ item.AttExt }}</a></div>

          <!-- <div>2</div>
               <div>3</div> -->

          <!-- <div v-for="(item, index) in fileList"  :key="index" style="text-align:left;background-color: #ffffff!important">{{item.AttName}}{{item.AttExt}}</div> -->
        </template>


      </van-field>
      <van-field class="input_text" label="备注" type="textarea" autosize :value="form.Remarks" readonly />
    </van-cell-group>
  </div>
</template>

<script>
import { getDetail } from "@/api/cert";
import { getTime, getDate } from "@/utils/getDate.js";
import { mapGetters } from "vuex";

export default {
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      certId: this.$route.query.certId,
      form: {},
      border: false,
      fileList: []
    };
  },
  beforeRouteLeave(to, from, next) {
    if (to.name == 'CertEdit') {
      to.meta.title = '编辑员工证书'
    }
    next()
  },
  created() {
    this.getDetail();
  },
  computed: {
    ...mapGetters(["roles"]),
  },
  methods: {
    getDetail() {
      let params = { id: this.certId };
      getDetail(params).then((res) => {
        res.data.PublishDate = getDate(res.data.PublishDate)
        res.data.ReviewDate = getDate(res.data.ReviewDate)
        res.data.NextReviewDate = getDate(res.data.NextReviewDate)

        this.form = res.data;
        this.fileList = []
        this.fileList = JSON.parse(res.data.Attachs2)
        console.log('asdadsa', JSON.parse(res.data.Attachs2));
      });
    },
    goReview(ucCode) {
      this.$router.push({
        path: "ReviewList",
        query: { ucCode: ucCode },
      });
    },
    // 编辑
    edit(certId) {
      // this.$router.push({
      //   path: "/Credential/Edit",
      //   query: { id: certId },
      // });

      this.$router.push({
        path: "/Credential/Edit",
        query: { id: certId },
      });
    },
    // 员工信息
    goStaffInfo() {
      this.$router.push("/Site_RiskUnit/StaffInfo");
    },
    // 检查记录
    goInspectRecord() {
      this.$router.push("/Site_RiskUnit/InspectRecord");
    },

    // 附件详情
    _goEnclosure(item) {
      // console.log(item,'sdvfdvdcd')
      this.$router.push({
        path: '/Credential/Enclosure',
        query: { attCode: item.AttCode },
      })
    },
  },
};
</script>

<style lang="less">
/*
        .main {
            height: 100vh;
        }
    */

.det_top_box {
  padding: 10px;
  background-color: #e8f1f8;
}

.detail_header {
  color: #ffffff;
  background: url("../../../assets/Images/AppIcon/image_riskunit_detail_bg.png");
  background-size: cover;
  padding: 10px;
  border-radius: 5px;
  /*background-color: #fff;*/

  .det_top {
    display: flex;
    justify-content: space-between;

    .dep_top_img {
      height: 20px;
      width: 20px;
      margin-right: 5px;
    }
  }

  .det_name {
    margin-top: 20px;
    text-align: center;
  }

  .det_location {
    text-align: center;
    margin-bottom: 20px;
  }
}

.det_tab {
  padding: 10px;

  .det_tab_item {
    padding: 10px 0;
    background-color: #fff;
    border-radius: 5px;
    margin-bottom: 10px;

    .det_tab_item_text {
      padding: 0 10px;
    }
  }
}

.text_box {
  padding: 10px;
  border-radius: 5px;
  /*background-color: #e8f1f8;*/
  margin-bottom: 10px;

  .text_top {
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;

    .top_link {
      color: #1989fa;
    }
  }

  .text_item {
    display: flex;
    justify-content: space-between;
    margin-left: 10px;

    .item_link {
      color: #1989fa;
    }
  }

  .text_img {
    display: flex;
    align-items: center;

    .img_item {
      width: 33.3%;
      text-align: center;

      img {
        height: 25px;
        width: 25px;
        margin-bottom: 10px;
      }
    }
  }

  .text_history {
    display: flex;
    vertical-align: middle;
    margin-bottom: 10px;
  }

  .text_member {
    color: #1989fa;
    margin-bottom: 10px;
  }

  .text_total_img {
    display: flex;
    align-items: center;

    .img_item {
      width: 33.3%;
      text-align: center;

      .img_item_top {
        display: flex;
        vertical-align: middle;
        margin-bottom: 10px;
      }

      img {
        height: 15px;
        width: 15px;
        margin-right: 5px;
      }
    }
  }

  .text_record_list {
    .list_row {
      display: flex;
      justify-content: space-between;
      margin-bottom: 10px;

      >div {
        width: 33.3%;
      }

      .row_center {
        text-align: center;
      }

      .row_right {
        text-align: right;
      }
    }
  }
}

.operate_det {
  background-color: #fff;
  padding: 10px;

  .operate_list {
    border: 1px solid #e8f1f8;

    .operate_row_first {
      padding: 10px;
      background-color: #e8f1f8;
      border-bottom: 1px solid #e8f1f8;
      margin-bottom: 10px;
      font-size: 14px;
    }

    .operate_row {
      padding: 10px;
      border-bottom: 1px solid #e8f1f8;
      font-size: 14px;
      /*margin-bottom: 10px;*/
    }
  }
}
</style>
